<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></meta>
<title>修改留言</title>
<script language="JavaScript">
function InputCheck(form1)
{
  if (form1.nickname.value == "")
  {
    alert("请输入您的昵称。");
    form1.nickname.focus();
    return (false);
  }
  if (form1.content.value == "")
  {
    alert("留言内容不可为空。");
    form1.content.focus();
    return (false);
  }
}
</script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="js/ajax.in.js"></script>
    <script src="tinymce/js/tinymce/tinymce.min.js"></script>
        <script>tinymce.init({
                selector: 'textarea',
                theme: "modern",
                language: "zh_CN",
                plugins: "advlist, anchor, autolink, autoresize, autosave, bbcode, charmap, code, codesample, colorpicker, compat3x, contextmenu, directionality, emoticons, fullpage, fullscreen, help, hr, image, imagetools, importcss, insertdatetime, legacyoutput, link, lists, media, nonbreaking, noneditable, pagebreak, paste, preview, print, save, searchreplace, spellchecker, tabfocus, table, template, textcolor, textpattern, toc, visualblocks, visualchars, wordcount, emoticons",
                // 使用的插件,有很多插件和工具栏按钮重复,可以去掉
                // 这里加载所有插件
                branding: false
            });</script>
</head>
<body>
<?php
require './core/conn.php';
if (! isset($_POST['id'])) {} else {
    $query_sql = "SELECT * FROM msg WHERE id = $_POST[id]";
    $result = mysqli_query($conn, $query_sql);
    // if (! $result)
    // exit('查询数据错误：' . mysqli_error());
    while (($gb_array = mysqli_fetch_array($result)) != false) {
        ?>
<div class="form">
		<form id="form1" name="form1" method="post" action="editmsgpost.php"
			onsubmit="return InputCheck(this)">
			<h3>修改留言</h3>
			<p>
				<input type="button" onclick="window.location.href='index.php'"
					value="首页" />
			</p>
			<p>
				<label for="title">昵&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称:</label>
				<input id="nickname" name="nickname" type="text"
					value="<?=$gb_array['nickname']?>" disabled="disabled" /><span>(必须填写，不超过16个字符串)</span>
			</p>
			<p>
				<label for="title">电子邮件:</label> <input id="email" name="email"
					type="text" value="<?=$gb_array['email']?>" /><span>(非必须，不超过60个字符串)</span>
			</p>
			<p>
				<label for="title">留言内容:</label>
				<textarea id="content" name="content" cols="50" rows="8"><?=br2nl(nl2br($gb_array['content']))?></textarea>
			</p>
			<input id="id" name="id" type="hidden" value="<?=$_POST['id']?>" /> <input
				type="button" onclick="history.go(-1)" value="返回"></input>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<!-- <input
				type="submit" name="submit" value="  确 定  " /> -->
			<button type="button" onclick="editMsg()">确定</button>
		</form>
	</div>
</body>
</html>
<?php
    }
}

// 删除留言
if (! isset($_GET['action'])) {} else {
    if ($_GET['action'] == 'delete') {
        $delete_sql = "DELETE FROM msg WHERE id = $_GET[id]";
        if (mysqli_query($conn, $delete_sql)) {
            exit('<script language="javascript">alert("删除成功！");self.location = "index.php";</script>');
        } else {
            exit('删除失败：' . mysqli_error() . '[ <a href="javascript:history.back()">返 回</a> ]');
        }
    }
}
?>